#######################
#                     #
#  PL0-Idiom Generator#
#                     #
#######################


### define generator class objects

###  Defined instructions for target-language
class Code_Instruction():
    def __setIns(self, name, op):
        if (op == 0):
            op = []
        elif (op == 1):
            op = [[]]
        elif (op == 2):
            op = [[],[]]
        elif (op == 3):
            op = [[],[],[]]
        self.instructions[name] = [name, op]
    
    def __init__(self):
        self.instructions = {}
        instruction_set = {'START': 0, 'HALT': 0, 'IN': 2, 'OUT': 2, 'LDN': 2, 'ADD': 3, 'SUB': 3, 'MUL': 3, 'DIV': 3, 'ADDN': 3, 'SUBN': 3, 'MULN': 3, 'DIVN': 3, 'JMP': 1, 'JMPZ': 1, 'JMPP': 1, 'JMPN': 1, 'LOAD': 2, 'STOR': 2, 'PUSH': 1, 'POP': 1, 'JSR': 1, 'RET': 0, 'DV': 1, 'DC': 1, 'DS': 1, 'postfix': 0, '': 0}
        for i in instruction_set:
            self.__setIns(i, instruction_set[i])
    

### Code instruction with three components: praefix, name, adress
### Used as object for instruction table generated during parsing
class Instruction():
    def __init__(self, preafix, name, adress):
        if (len(adress) == len(Code_Instruction().instructions[name][1])): self.ins = [preafix, Code_Instruction().instructions[name][0], adress]    
        

### instruction list
class InstructionList():
    def __init__(self):
        self.list = []
        self.stack = []
        
    def addIns(self, p, n, a):
        self.list.append(Instruction(p, n, a))
        